<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>给一个偶数，拆成两个质数的和</title>
</head>
<body>
    <script>
        //因数个数函数
        //console.log(ysgs(10));
        function ysgs(num){
            var sum = 0;
            for(var i = 1;i<=num;i++){
                if(num%i==0){
                    sum++
                }
            }
            return sum;
        }
        //判断质数
        // console.log(pdzs(3));
        function pdzs(num){
            if(ysgs(num) == 2){
                return true;
            }else{
                return false;
            }
        }
        //列出num以内的质数
        // console.log(lczs(10));
        function lczs(num){
            var arr = []
            for(var i = 1;i<=num;i++){
                if(pdzs(i)){
                    arr.push(i)
                }
            }
            return arr;
        }
        console.log(sum(31));
        function sum(ns){
            var arr = []
            for(var i=1;i<ns;i++){
                if(pdzs(i)&&pdzs(ns-i)){
                    arr.push(i+"和"+(ns-i))
                }  
             }
            if(arr.length==0){
                    arr = ["没有"]
                }
            return arr; 
        }
    </script>
</body>
</html>